using System;
using Microsoft.Xna.Framework;
using Itdavany.Utility;
using Itdavany.Data;
using Itdavany.Objects;

namespace RollingKitty.Objects
{
    public class PopupMenu : Widget
    {
        public new Scene SubScene
        {
            get { return base.SubScene; }
        }

        public event EventHandler MenuPoppedUp;

        public PopupMenu()
        {
            //IsHidden = true;
        }

        public void SetParent(Button prnt) {
            prnt.LeftClicked += new EventHandler(OnParentClick);
        }

        public void LinkChilds()
        {
            foreach(GameObjectGroup layer in SubScene)
            foreach (GameObject obj in layer)
            {
                ((Button)obj).LeftClicked += new EventHandler(OnChildClick);
            }
        }

        protected void OnParentClick(object obj, EventArgs e)
        {
            IsHidden = !IsHidden;
            if (!IsHidden)
                MenuPoppedUp(this, EventArgs.Empty);
        }

        protected void OnChildClick(object obj, EventArgs e)
        {
            IsHidden = true;
        }
        /*
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            if (HitTest(new Vector2(MouseInput.X, MouseInput.Y)) && IsHidden)
                IsHidden = true;
            else if(!HitTest(new Vector2(MouseInput.X, MouseInput.Y)) && !IsHidden)
                IsHidden = false;

            base.Update(gameTime);
        }*/
    }
}